<!--
 * @Author: zengwj
 * @Date: 2021-09-22 14:58:57
 * @LastEditors: zengwj
 * @LastEditTime: 2021-09-22 17:17:33
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /**
       * @param {number} n
       * @param {number} k
       * @return {number[][]}
       */
      let path = [];
      let res = [];
      var combine = function (n, k) {
        path = [];
        backtracking(n, k, 1);
        return res;
      };
      const backtracking = function (nums, k, start) {
        if (path.length === k) {
          res.push([...path]);
          return;
        }
        for (let i = start; i <= nums; i++) {
          path.push(i);
          backtracking(nums, k, i + 1);
          path.pop();
        }
      };
      console.log(combine(1, 1));
    </script>
  </body>
</html>
